﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EBA.Framework
{
    /// <summary>
    /// 远程跨域地址
    /// </summary>
    public static class RemotingUris
    {
        /// <summary>
        /// 运行时全局跨域通道名称
        /// </summary>
        /// <param name="runtime"></param>
        /// <param name="bundleId"></param>
        /// <returns></returns>
        public static string BuildRuntimeChannelName(string runtime, string bundleId)
        {
            return string.Format("Runtime-{0}",runtime);
        }

        /// <summary>
        /// 指定插件跨域通道名称
        /// </summary>
        /// <param name="runtime"></param>
        /// <param name="bundleId"></param>
        /// <returns></returns>
        public static string BuildBundleChannelName(string runtime, string bundleId)
        {
            return string.Format("{0}-bundle-{1}", runtime, bundleId);
        }

        /// <summary>
        /// 指定插件可使用的插件跨域调用对象地址
        /// </summary>
        /// <param name="bundleId"></param>
        /// <param name="serviceType"></param>
        /// <returns></returns>
        public static string BuildServiceUri(string runtime, string bundleId,Type serviceType)
        {
            return string.Format("{0}-Service-{1}-{2}",runtime, bundleId, serviceType.FullName);
        }

        /// <summary>
        ///获取插件的上下文跨域调用对象地址
        /// </summary>
        /// <param name="runtime"></param>
        /// <param name="bundleId"></param>
        /// <returns></returns>
        public static string BuildBundleContextUri(string runtime, string bundleId)
        {
            return string.Format("{0}-BundleContext-{1}",runtime, bundleId);
        }

        /// <summary>
        ///获取插件的同步对象跨域调用对象地址
        /// </summary>
        /// <param name="runtime"></param>
        /// <param name="bundleId"></param>
        /// <returns></returns>
        public static string BuildRuntimeSyncEventUri(string runtime, string bundleId)
        {
            return string.Format("{0}-SyncEvent-{1}", runtime, bundleId);
        }

        /// <summary>
        ///获取插件的同步对象跨域调用对象完整地址
        /// </summary>
        /// <param name="runtime"></param>
        /// <param name="bundleId"></param>
        /// <returns></returns>
        public static string BuildFullRuntimeSyncEventUri(string runtime, string bundleId)
        {
            return string.Format("ipc://Runtime-{0}/{0}-SyncEvent-{1}", runtime, bundleId);
        }


        /// <summary>
        ///获取插件跨域调用对象完整地址
        /// </summary>
        /// <param name="runtime"></param>
        /// <param name="bundleId"></param>
        /// <returns></returns>
        public static string BuildFullBundleUri(string channelName, string bundleId)
        {
            return string.Format("ipc://{0}/{1}", channelName, bundleId);
        }
    }
}
